<?php
namespace dingtalk;

use dingtalk\util\Http;

class Dept
{

    /**
     * 部门列表
     * @param $accessToken
     * @return mixed
     */
    public static function listDept($accessToken,$id=1)
    {
        $response = Http::get("/department/list", ["access_token" => $accessToken,"id"=>$id]);
        return obj2array($response);
    }

    /**
     * 部门详情
     * @param $accessToken
     * @return mixed
     */
    public static function getDept($accessToken, $id=1)
    {
        $response = Http::get("/department/get", ["access_token" => $accessToken,"id"=>$id]);
        return obj2array($response);
    }

    /**
     * 创建部门
     * @param $accessToken
     * @param $dept
     * @return mixed
     */
    public static function createDept($accessToken, $dept)
    {
        $response = Http::post("/department/create", ["access_token" => $accessToken], json_encode($dept));
        return obj2array($response);
    }

    /**
     * 更新部门
     * @param $accessToken
     * @param $dept
     * @return mixed
     */
    public static function updateDept($accessToken, $dept)
    {
        $response = Http::post("/department/update", ["access_token" => $accessToken], json_encode($dept));
        return obj2array($response);
    }

    /**
     * 删除部门
     * @param $accessToken
     * @param $id
     * @return bool
     */
    public static function deleteDept($accessToken, $id)
    {
        $response = Http::get("/department/delete", ["access_token" => $accessToken, "id" => $id]);
        return obj2array($response);
    }

    /**
     * 按部门查询部门上级
     * @param $accessToken
     * @param $id
     * @return mixed
     */
    public static function parentDeptByDept($accessToken, $id)
    {
        $response = Http::get("/department/list_parent_depts_by_dept", ["access_token" => $accessToken, "id" => $id]);
        return obj2array($response);
    }

    /**
     * 按用户查询部门上级
     * @param $accessToken
     * @param $id
     * @return mixed
     */
    public static function parentDeptByUser($accessToken, $userId)
    {
        $response = Http::get("/department/list_parent_depts", ["access_token" => $accessToken, "userId" => $userId]);
        return obj2array($response);
    }
}